from rest_framework import serializers

from apps.Persions.models import UserProfile, LoginInfer


class UserProfileSerializer(serializers.ModelSerializer):
    """
    简单用户序列化器
    """
    admin = serializers.SerializerMethodField(read_only=True)
    deptId = serializers.IntegerField(source='dept.id', read_only=True)
    # 未读通知数量
    unread_msg_count = serializers.SerializerMethodField(read_only=True)

    def get_admin(self, obj: UserProfile):
        return True
        # role_list = obj
        # if True in list(set(role_list)):
        #     return True
        # return False

    def get_unread_msg_count(self, obj: UserProfile):
        return "hello world"

    class Meta:
        model = UserProfile
        fields = '__all__'
        depth = 1
        # exclude = ('password', 'secret', 'user_permissions', 'groups', 'is_superuser', 'date_joined')


class LoginInferSerializer(serializers.ModelSerializer):
    """
    登录日志 简单序列化器
    """
    creator = serializers.SerializerMethodField(read_only=True)
    browser = serializers.SerializerMethodField(read_only=True)

    def get_browser(self, obj: LoginInfer):
        return "test_01"

    def get_creator(self, obj: LoginInfer):
        return "test_02"

    class Meta:
        model = LoginInfer
        fields = "__all__"
